package com.syygl.test.study.middleware.rabbitMQ;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class MsgProducer {

    //使用RabbitTemplate进行操作
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 向扇形交换器发送数据
     *
     * @param routingKey
     * @param massage
     */
    public void send2FanoutTestQueue(String routingKey, String massage) {
        rabbitTemplate.convertAndSend(RabbitConfig.TEST_FANOUT_EXCHANGE,
                routingKey, massage);
    }

    /**
     * 向直接交换器发送数据
     *
     * @param routingKey
     * @param massage
     */
    public void send2DirectTestQueue(String routingKey, String massage) {
        rabbitTemplate.convertAndSend(RabbitConfig.TEST_DIRECT_EXCHANGE,
                routingKey, massage);
    }

    /**
     * 向主题交换器发送数据
     *
     * @param routingKey
     * @param massage
     */
    public void send2TopicTestAQueue(String routingKey, String massage) {
        rabbitTemplate.convertAndSend(RabbitConfig.TEST_TOPIC_EXCHANGE,
                routingKey, massage);
    }

}

